package com.tancire.web.controller.member;

import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.core.page.TableDataInfo;
import com.tancire.common.enums.BusinessType;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.net.domain.NetUser;
import com.tancire.net.service.INetUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 会员管理Controller
 *
 * @author chenchao
 * @date 2022-11-06
 */
@RestController
@RequestMapping("/net/netUser")
public class NetUserController extends BaseController {

    @Resource
    private INetUserService netUserService;

    /**
     * 查询会员管理列表
     */
    @PreAuthorize("@ss.hasPermi('net:netUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(NetUser netUser) {
        startPage();
        List<NetUser> list = netUserService.selectNetUserList(netUser);
        return getDataTable(list);
    }

    /**
     * 导出会员管理列表
     */
    @PreAuthorize("@ss.hasPermi('net:netUser:export')")
    @Log(title = "会员管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NetUser netUser) {
        List<NetUser> list = netUserService.selectNetUserList(netUser);
        ExcelUtil<NetUser> util = new ExcelUtil<NetUser>(NetUser.class);
        util.exportExcel(response, list, "会员管理数据");
    }

    /**
     * 获取会员管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('net:netUser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(netUserService.selectNetUserById(id));
    }

    /**
     * 新增会员管理
     */
    @PreAuthorize("@ss.hasPermi('net:netUser:add')")
    @Log(title = "会员管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NetUser netUser) {
        return toAjax(netUserService.insertNetUser(netUser));
    }

    /**
     * 修改会员管理
     */
    @PreAuthorize("@ss.hasPermi('net:netUser:edit')")
    @Log(title = "会员管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NetUser netUser) {
        return toAjax(netUserService.updateNetUser(netUser));
    }

    /**
     * 删除会员管理
     */
    @PreAuthorize("@ss.hasPermi('net:netUser:remove')")
    @Log(title = "会员管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(netUserService.deleteNetUserByIds(ids));
    }
}
